import { defineStore } from "pinia";
import {getUserInfo} from "@/api/acconut.js";

export const userInform = defineStore('userinfor',{
    state:()=>{
        return{
            userId:'',
            avatarUrl:'',
            username:'',
            token:''
        }
    },
    actions:{
        async setUserInformData(username) {
             const res = await getUserInfo(username)
             this.userId = res.data.userId
             this.avatarUrl = res.data.avatarUrl
             this.username = res.data.username
         },
        setToken (token){
            this.token = token
        },
        clearUserInformData (){
            this.userId = ''
            this.avatarUrl = ''
            this.username = ''
        },
        clearToken (){
            this.token = ''
        },
        clearAll(){
            this.clearUserInformData()
            this.clearToken()
        }
    }
},{
    persist:{
        //存储用户
        enabled:true,
        // 关键字
        key:'userInform',
        storage:localStorage,
    }
})